#!/usr/bin/python
# vim: fdm=marker fmr={{{,}}} cms=#%s

import sys
import os
import re

SOAR=os.environ.get('SOAR')
if not SOAR:
    SOAR='/opt/soar'
sys.path.append(SOAR+'/common/python')
try:
    from soar import *
except ImportError:
    print >>sys.stderr, """\
Import soar fail
%s
%s
""" % (sys.exc_value, sys.version)
    sys.exit(1)

def usage(selfname):
#{{{
    print "Usage: %s host:port service [ para... ]" % selfname
#}}}

def main(argc, argv):
#{{{
    if argc < 3:
        usage(argv[0])
        return 1

    sn=svcnode.svcnode(argv[1], svcnode.ONESHOT)
    svc=argv[2]
    req=''
    for item in argv[3:]:
        req,size=para.put_item(req, item)
    try:
        resp=sn.call(svc, req)
    except svcnode.error,e:
        print "svcnode call fail: %d" % e.errcode
        resp=''
        resp=para.put_item(resp, e.errcode)
    curr=0
    while 1:
        item,curr=para.get_item(resp, curr)
        if not item: break
        print item
#}}}

if __name__ == '__main__':
    main(len(sys.argv), sys.argv)
